package com.quasar.hpatient.module.comm_album;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.quasar.hpatient.R;
import com.quasar.hpatient.bean.comm_album.AlbumFolderBean;
import com.quasar.hpatient.module.comm_album_folder.AlbumFolderFragment;
import com.quasar.hpatient.module.comm_album_photo.AlbumPhotoFragment;

import java.util.Map;

import lib.quasar.context.BaseApp;

/**
 * description: 选择图片
 * created by kalu on 2018/4/18 15:53
 */
public class AlbumAdapter extends FragmentPagerAdapter {

    private AlbumPhotoFragment mAlbumPhotoFragment = new AlbumPhotoFragment();
    private AlbumFolderFragment mAlbumFolderFragment = new AlbumFolderFragment();

    public AlbumAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public Fragment getItem(int position) {
        return position == 0 ? mAlbumPhotoFragment : mAlbumFolderFragment;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        Context context = BaseApp.getContext();
        return context.getResources().getString(position == 0 ? R.string.comm_album_photo : R.string.comm_album_folder);
    }

    void setPhotoList(Map<String, AlbumFolderBean> map) {
        if (null == mAlbumPhotoFragment || null == mAlbumFolderFragment) return;
        final String folder = BaseApp.getResource().getString(R.string.comm_album_all);
        mAlbumPhotoFragment.setPhotoList(map, folder);
        mAlbumFolderFragment.setPhotoList(map);
    }

    void changeFolder(Map<String, AlbumFolderBean> map, String folder) {
        if (null == mAlbumPhotoFragment) return;
        mAlbumPhotoFragment.setPhotoList(map, folder);
    }

    void setResult() {
        if (null == mAlbumPhotoFragment) return;
        mAlbumPhotoFragment.setResult();
    }
}